package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00107.BaseDay00107Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00107.BaseDay00107Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00107.BaseDay00107Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00107.BaseDay00107Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00107.BaseDay00107Presenter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00108.BaseDay00108Contion;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay00107 extends BasterFragment implements BaseDay00107Contion.vier, OnRefreshLoadMoreListener {


    public BaseDay00107Adpter adpter ;
    public static SmartRefreshLayout day00107SmartRefreshLayout;
    private RecyclerView day00107RecyclerView;
    public int paer = 60;
    public int qizhi=0;
    public boolean ispaer = true;
    public BaseDay00107Presenter presenter;

    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00107;
    }

    @Override
    public void initView() {

        day00107SmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.day00107_SmartRefreshLayout);
        day00107SmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        day00107RecyclerView = (RecyclerView) findViewById(R.id.day00107_RecyclerView);
        day00107RecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));

        presenter = new BaseDay00107Presenter(this,new BaseDay00107Model());
        presenter.dogetin("/video/findVideos?currentPage="+paer+"&pageSize=10");
    }

    @Override
    public void initDate() {

    }


    @Override
    public void getvier(List<BaseDay00107Bean.DataBean> dataBeans) {
        for (BaseDay00107Bean.DataBean dataBean : dataBeans) {
            dataBean.setNihaoma(++qizhi);
            if (qizhi==4){
                qizhi=0;
            }
        }
        day00107SmartRefreshLayout.finishLoadMore();
        day00107SmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new BaseDay00107Adpter(dataBeans);
            day00107RecyclerView.setAdapter(adpter);
        }else {
            if (ispaer){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }

    }


    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        ispaer=false;
        paer++;
        presenter.dogetin("/video/findVideos?currentPage="+paer+"&pageSize=10");
        Log.i("BlankFragmentDay001","--07加载:"+paer);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (ispaer){
            paer=60;
        }
        presenter.dogetin("/video/findVideos?currentPage="+paer+"&pageSize=10");
        Log.i("BlankFragmentDay001","--07刷新:"+paer);
    }
}
